package com.fwixvye.controller;

import cn.hutool.json.JSONUtil;
import com.fwixvye.pojo.*;
import com.fwixvye.pojo.Character;
import com.fwixvye.service.CharacterDamageCalculationDetailedService;
import com.fwixvye.utils.OcrUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.util.Base64;

@RestController
@RequestMapping("/CharacterDamageCalculationDetailed")
public class CharacterDamageCalculationDetailedController {


    @Autowired
    private CharacterDamageCalculationDetailedService detailedService;

    @PostMapping("/ScreenshotOfEntry")
    public Result ScreenshotOfEntry(
            @RequestPart("screenshot") MultipartFile file,
            @RequestParam("charer") String characterStr,
            @RequestParam("weapon") String weaponStr,
            @RequestParam("relics1") String relics1Str,
            @RequestParam("relics2") String relics2Str,
            @RequestParam("role") String roleStr
    ) throws IOException {


        Character character = JSONUtil.toBean(characterStr, Character.class);
        Weapon weapon = JSONUtil.toBean(weaponStr, Weapon.class);
        Relics relics1 = JSONUtil.toBean(relics1Str, Relics.class);
        Relics relics2 = JSONUtil.toBean(relics2Str, Relics.class);
        Role role = JSONUtil.toBean(roleStr, Role.class);


        return detailedService.ScreenshotOfEntry(file, character, weapon, relics1, relics2, role);
    }

    @PostMapping("/SubmitForCalculation")
    public Result SubmitForCalculation(@RequestBody Role role) {



        return detailedService.SubmitForCalculation(role);

    }
}
